home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / Item Class / Item sources / CTableExpander.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-30  |  2.6 KB  |  120 lines  |  [TEXT/KAHL]

  1. /*
  2.  * File:        CTableExpander.c
  3.  * Created:        8/1/93
  4.  * Desc:        A mousetask that handles drawing the expando icon.
  5.  *
  6.  * Superclass:    CTableDragger.
  7.  * Uses:        CItemTable, CItem.
  8.  * Original Author:    W. Wesley Monroe
  9.  * Modifications:    
  10.  *
  11.  * Copyright © 1993 Animas Software Production. All rights reserved.
  12.  */
  13.  
  14. #include "CTableExpander.h"
  15. #include "CItemTable.h"
  16. #include "CItem.h"
  17. #include    <Icons.h>
  18.  
  19. enum {
  20.     kArrowCollapsed = 131,
  21.     kArrowTransition,
  22.     kArrowExpanded
  23. };
  24.  
  25. #define    kCellLevelIndent    16
  26.  
  27. void CTableExpander::ITableExpander(CTable *aTable, short theModifiers,
  28.                                   long selFlags, CItem *item, Rect iconR)
  29. {
  30.     short    expanded;
  31.  
  32.     ITableDragger(aTable, theModifiers, selFlags);
  33.  
  34.     fSelItem = item;
  35.  
  36.     ASSERT(item);
  37.     fExpanded = item->GetExpanded();
  38.     fIndentLeft =  item->GetLevel()*kCellLevelIndent;
  39.  
  40.     fInTriangle = TRUE;
  41.     fInverted = 0;
  42.     fIconR = iconR;
  43.     fArrowICNid2 = kArrowTransition;
  44.     fArrowICNid1 = fExpanded ? kArrowExpanded : kArrowCollapsed;
  45.     fArrowICNid3 = !fExpanded ? kArrowExpanded : kArrowCollapsed;
  46. }
  47.  
  48. void CTableExpander::BeginTracking( LongPt *startPt)
  49. {
  50.     Rect        r;
  51.  
  52.     r = fIconR;
  53.     ((CItemTable *) itsTable)->Draw7Icon(&r, 0, fArrowICNid1,ttSelected);
  54. }
  55.  
  56. void CTableExpander::KeepTracking(LongPt *currPt, LongPt *prevPt,
  57.                                 LongPt *startPt)
  58. {
  59.     LongRect    lr;
  60.     Rect        r;
  61.     short        inOut;
  62.  
  63.     r = fIconR;
  64.     QDToLongRect(&r, &lr);
  65.     fInTriangle = PtInLongRect(currPt, &lr);
  66.  
  67.     if(fInTriangle == 1 && fInverted == 0) {
  68.  
  69.         fInverted = 1;
  70.         ((CItemTable *) itsTable)->Draw7Icon(&r, 0, fArrowICNid1,ttSelected);
  71.     } else if(fInTriangle == 0 && fInverted == 1) {
  72.  
  73.         fInverted = 0;
  74.         ((CItemTable *) itsTable)->Draw7Icon(&r, 0, fArrowICNid1,ttNone);
  75.     }
  76. }
  77.  
  78. /*
  79.  * EndTracking()
  80.  *
  81.  *    If released in the expando icon,
  82.  *        - Animate the expando icon,
  83.  *        - Send the setexpand message to the hitCell,
  84.  *        - Send the expandCell message to the hitCell.
  85.  *    else
  86.  *        - just redraw the icon.
  87.  */
  88.  
  89. void CTableExpander::EndTracking(LongPt *currPt, LongPt *prevPt,
  90.                                LongPt *startPt)
  91. {
  92.     CItem    *aItem = fSelItem;
  93.     Cell    hitCell;
  94.     Rect    iconRect;
  95.  
  96.     iconRect = fIconR;
  97.     itsTable->FindHitCell(startPt, &hitCell);
  98.  
  99.     if(fInTriangle == 1) {
  100.  
  101.         long    ts;
  102.  
  103.         ((CItemTable *) itsTable)->DrawTriangle(&iconRect, 0, fArrowICNid1);
  104.         ts = TickCount();
  105.         while(ts + 5 > TickCount());
  106.         ((CItemTable *) itsTable)->DrawTriangle(&iconRect, 0, fArrowICNid2);
  107.         ts = TickCount();
  108.         while(ts + 5 > TickCount());
  109.         ((CItemTable *) itsTable)->DrawTriangle(&iconRect, 0, fArrowICNid3);
  110.         fExpanded = !fExpanded;
  111.  
  112.         aItem->SetExpanded(fExpanded);
  113.         ((CItemTable *) itsTable)->ExpandCell(hitCell, fExpanded);
  114.  
  115.     }
  116.     else
  117.         ((CItemTable *) itsTable)->DrawTriangle(&iconRect,
  118.                                                 0, fArrowICNid1);
  119.  
  120. }